<template>
  <div class="transactionProgress">
    <div class="title">
      交易进度
    </div>
    <!-- 表格 -->
    <el-table :data="initData.list" style="width: 100%">
      <el-table-column align="center" header-align="center" prop="title" label="交易信息">
      </el-table-column>
      <el-table-column align="center" header-align="center" prop="progress" label="当前进度">
        <template slot-scope="scope">
          {{scope.row.progress}}{{((key)=>{
            switch(key){
              case 1: return '(已完成)';break;
            }
          })(scope.row.state)}}
        </template>
      </el-table-column>
      <el-table-column align="center" header-align="center" prop="createdAt" label="日期">
        <template slot-scope="scope">
          {{$util.formDate(scope.row.createdAt)}}
        </template>
      </el-table-column>
      <el-table-column align="center" header-align="center" label="交易操作" width="100">
        <template slot-scope="scope">
          <el-popconfirm title="确定删除此进度吗？" v-show="scope.row.state == 1" @confirm="delPro(scope.row)">
            <el-button type="danger" slot="reference">删除</el-button>
          </el-popconfirm>
          <!-- <el-button v-show="scope.row.state == 1" type="danger" @click="delPro(scope.row)">删除</el-button> -->
        </template>
      </el-table-column>

    </el-table>

    <!-- 分页 -->
    <el-pagination @current-change="handleCurrentChange" :current-page="params.page" :page-size="10" layout="total, prev, pager, next" :total="params.total">
    </el-pagination>

  </div>
</template>

<script>
export default {
  name: "transactionProgress",
  data() {
    return {
      initData: {
        list: [
          // {
          //   id: 1,
          //   title: "金碧花园三期二手房交易",
          //   progress: "等待付款",
          //   state: 0,// 0进行中 1已完成
          // },
          // {
          //   id: 1,
          //   title: "金碧花园三期二手房交易",
          //   progress: "准备合同",
          //   state: 1,// 0进行中 1已完成
          // },


        ]
      },
      params: {
        page: 1,
        total: 0,
      },
    }
  },
  created() {
    this.init();
  },
  methods: {
    init() {
      this.axios({
        method: 'get',
        url: this.baseUrl + '/getProgress',
        params: {
          userId: this.$cookies.get("__ui"),
          page: this.params.page
        }
      }).then(res => {
        console.log('res==>', res)
        if (res.data.code == 400) {
          this.$message.error(res.data.msg)
        } else {
          this.initData.list = res.data.data;
          this.params.total = res.data.total;
        }
      }).catch(err => {
        console.log('err==>', err)
        this.$message.error(res.data.msg)
      })
    },
    // 当前页
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.params.page = val;
      this.init();
    },
    // 删除进度
    delPro(o) {
      console.log('删除==>', o)
      this.axios({
        method: 'delete',
        url: this.baseUrl + '/deleteProgress',
        data: {
          id: o.id,
          isDel: 1
        }
      }).then(res => {
        console.log('res==>', res)
        if (res.data.code == 200) {
          this.$message.success(res.data.msg)
          setTimeout(() => {
            this.init();
          }, 1000);
        } else {
          this.$message.error(res.data.msg)
        }
      }).catch(err => {
        console.log('err==>', err)
        this.$message.error(res.data.msg)
      })
    },
  },
}
</script>

<style lang="less" scoped>
.transactionProgress {
  .title {
    font-size: 20px;
    font-weight: bold;
    color: #000;
    margin-bottom: 20px;
  }
  .el-pagination {
    margin-top: 30px;
    text-align: center;
  }
}
</style>